package com.cicro.oauth_sso.sso_auth_resource_server.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

@Configuration
@EnableAuthorizationServer
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
            .withClient("javaboy")
            .secret(passwordEncoder.encode("123"))
            .autoApprove(true)
            .redirectUris("http://localhost:1112/login", "http://localhost:1113/login")
            .scopes("user")
            .accessTokenValiditySeconds(7200)
            .authorizedGrantTypes("authorization_code");
    }
}
